<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

# Author    :  ELIZAR M. FLORES
# Copyright : Copyright? what do you mean copyright? The best thing in programming is OPEN SOURCE. So go ahead dig in.
#             If you know what you are doing, MODIFY and IMPROVE.
#             If you dont know what you are doing, READ and ASK.
#             If you are a hacker, Go somewhere else. 
#             If you are rich, Go ahead... DONATE!


class Model_posts extends CI_Model{
    
    
     public function get_user_post($id,$type='MEMBER',$order='DESC',$limit='0,10')
         {
           $key  = array('posted_as'=>$type,'posted_as_id'=>$id);
           $post = new QUERY(array('TABLE'=>'posts','KEY'=>$key,$order=>'posted_on','LIMIT'=>$limit));
        
           $all = $post->fetchAll();
           return $all;
         }
         
      public function get_group_post($group_id,$order=' ORDER BY posted_on DESC',$limit=' LIMIT 0,10')
        {
          $query  = "SELECT * FROM posts p JOIN group_assignment g WHERE g.group_id     = :id      AND 
                                                                         p.posted_as    = 'MEMBER' AND 
                                                                         p.permission   ='GROUP'   AND 
                                                                         p.posted_as_id = g.member_id
                                                                         $order $limit";
          $params = array('id'=>$group_id);
          $post   = new QUERY();
          
          $result = $post->run($query, $params)->fetchAll(pdo::FETCH_ASSOC);
          return $result;
       } 
	
}
?>